#include <stdio.h>
#include <string.h>
#include <stdlib.h>


//struct stu
//{
//    char name[100];
//    int num;
//    char sex;
//    float score;
//};

typedef struct stu
{
    char name[100];
    int num;
    char sex;
    float score;
} Stu;

// 初始化是一种特殊的语法 跟赋值不等价
// 凡是 基本类型，既可以在定义的时候初始化，也可以先定义再赋值。
// 凡是 构造类型，要么在定义的时候初始化，不可以先定义再初始化的方式赋值。

// 初始化，成员赋值
// 其他初始化方法：https://blog.csdn.net/linux_wgl/article/details/51924191

int main1()
{
    int a;
    a = 10;
    int arr[10] = {1,2,3,4,5};

    //    struct stu s={"zhangsan",1001,'f',99};
    struct stu s;
//    strcpy(s.name,"zhangsan");
////    s.name = "zhangsan";
//    s.num = 1001;
//    s.sex = 'f';
//    s.score = 59;
//    scanf("%s%d %c%f",s.name,s.num,s.sex,s.score);
//        scanf("%s%d %c%f",&s.name,&s.num,&s.sex,&s.score);
    scanf("%s%d %c%f",s.name,&s.num,&s.sex,&s.score);
    printf(" name: %s\n num: %d \n sex: %c\n score: %f\n",
           s.name,s.num,s.sex,s.score);
    return 0;
}

// 访问
// 一类在栈上  一类在堆上
// 点成员运算符，指向成员运算符


int main2 ()
{
    struct stu s={"zhangsan",1001,'f',99};
    struct stu *ps = &s;
    // s.name s.num s.sex ....
    printf("name  = %s\n",ps -> name);
    printf("num   = %d\n",ps -> num);
    printf("sex   = %c\n",ps -> sex);
    printf("score = %f\n",ps -> score);

    // *ps == s ??
    printf("name  = %s\n",(*ps).name);
    printf("num   = %d\n",(*ps).num);
    printf("sex   = %c\n",(*ps).sex);
    printf("score = %f\n",(*ps).score);
    return 0;
}



// 访问
// 一类在栈上  一类在堆上
int main()
{
    Stu *ps =(Stu*)malloc(sizeof (Stu));
    strcpy(ps->name,"zhaoliu");
    ps->num = 1006;
    ps ->sex='x';
    ps ->score = 88;
    printf("name  = %s\n",ps -> name);
    printf("num   = %d\n",ps -> num);
    printf("sex   = %c\n",ps -> sex);
    printf("score = %f\n",ps -> score);

    printf("name  = %s\n",(*ps).name);
    printf("num   = %d\n",(*ps).num);
    printf("sex   = %c\n",(*ps).sex);
    printf("score = %f\n",(*ps).score);

    free(ps);
    return 0;
}
